package com.weixin.paleituo.activity;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.weixin.paleituo.R;
import com.weixin.paleituo.adapter.LivingPaymentGridAdapter;
import com.weixin.paleituo.base.BaseActivity;
import com.weixin.paleituo.bean.ProductListBean;
import com.weixin.paleituo.util.ToastUtils;
import com.weixin.paleituo.view.MyGridView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindArray;
import butterknife.BindView;
import butterknife.OnClick;

public class LivingPaymentActivity extends BaseActivity {


    @BindView(R.id.iv_back_activity_basepersoninfo)
    ImageView mIvBackActivityBasepersoninfo;
    @BindView(R.id.tv_title_activity_baseperson)
    TextView mTvTitleActivityBaseperson;
    @BindView(R.id.tv_small_title_layout_head)
    TextView mTvSmallTitleLayoutHead;
    @BindView(R.id.rl_head_root_activity_baseperson)
    RelativeLayout mRlHeadRootActivityBaseperson;
    @BindView(R.id.mygrideview_activity_living_payment)
    MyGridView mMygrideviewActivityLivingPayment;
    int[] icons = {R.mipmap.icon_wuye, R.mipmap.icon_water, R.mipmap.icon_dian, R.mipmap.icon_ranqi};
    @BindArray(R.array.livingpayments)
    String[] names;

    @Override
    protected void initView() {
        setContentView(R.layout.activity_living_payment);

    }


    @OnClick(R.id.iv_back_activity_basepersoninfo)
    public void onMIvBackActivityBasepersoninfoClicked() {
        finish();
    }

    @Override
    protected void initData() {
        super.initData();
        mTvTitleActivityBaseperson.setText("生活缴费");
        List<ProductListBean> productListBeans = new ArrayList<>();
        ProductListBean productListBean;
        for (int i = 0; i < names.length; i++) {
            productListBean = new ProductListBean(names[i], icons[i]);
            productListBeans.add(productListBean);
        }
        LivingPaymentGridAdapter livingPaymentGridAdapter = new LivingPaymentGridAdapter(this, productListBeans);
        mMygrideviewActivityLivingPayment.setAdapter(livingPaymentGridAdapter);
    }
/*  //生活缴费
                                    *//*WATER：缴水费
                            ELECTRIC：缴电费
                            GAS：缴燃气费
                            COMMUN：缴固话宽带
                            CATV：缴有线电视费
                            TRAFFIC：缴交通罚款
                            WUYE：缴物业费
                            HK：信用卡还款
                            CZ：手机充值*//*

                        String url="alipays://platformapi/startapp?appId=20000193";
//String url="alipays://platformapi/startapp?appId=20000193&url=/www/setNewAccount.htm?subBizType=";
        try {
            Intent intent;
            intent = Intent.parseUri(url,
                    Intent.URI_INTENT_SCHEME);
            intent.addCategory("android.intent.category.BROWSABLE");
            intent.setComponent(null);
            // intent.setSelector(null);
            startActivity(intent);

        } catch (Exception e) {
            ToastUtils.makeText("请安装支付宝");
        }*/

    @Override
    protected void initEvent() {
        super.initEvent();
        mMygrideviewActivityLivingPayment.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String url="";
                switch (position) {
                    case 0:
                        //物业
                        WuyePaymentActivity.myStartActivity(LivingPaymentActivity.this);
                        break;
                    case 1:
                        //水费
                         url="alipays://platformapi/startapp?appId=20000193&url=/www/setNewAccount.htm?subBizType=WATER";
                        jumpZhiFuBao(url);
                        break;
                    case 2:
                        //电费
                        url="alipays://platformapi/startapp?appId=20000193&url=/www/setNewAccount.htm?subBizType=ELECTRIC";
                        jumpZhiFuBao(url);
                        break;

                    case 3:
                        //燃气费
                        url="alipays://platformapi/startapp?appId=20000193&url=/www/setNewAccount.htm?subBizType=GAS";
                        jumpZhiFuBao(url);
                        break;
                }


            }
        });
    }

    private void jumpZhiFuBao(String url) {
        try {
            Intent intent;
            intent = Intent.parseUri(url,
                    Intent.URI_INTENT_SCHEME);
            intent.addCategory("android.intent.category.BROWSABLE");
            intent.setComponent(null);
            // intent.setSelector(null);
            startActivity(intent);
        } catch (Exception e) {
            ToastUtils.makeText("请安装支付宝");
        }
    }

    public static void myStartActvity(Context context) {
        Intent intent = new Intent(context, LivingPaymentActivity.class);
        context.startActivity(intent);


    }

}
